<template>
	<div>
		<vxe-modal v-model="dialogVisible" title="请填写型号相关信息" width="800" height="320" show-zoom resize remember>
			<template #default>
				<vxe-form title-colon ref="xForm" title-align="right" title-width="130" :data="formData2"
					:rules="formRules2" :loading="loading2" @submit="submitEvent2" @reset="resetEvent">
					<vxe-form-gather span="12">
						<vxe-form-item title="型号名称"  field="batModel" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.batModel" placeholder="请输入型号名称" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
						<vxe-form-item title="保质期(年)"  field="exp" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.exp" type="number" placeholder="请输入保质期" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
						<vxe-form-item title="电池单体数量"  field="singBatNum" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.singBatNum" type="number" placeholder="请输入电池单体数量" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
						<vxe-form-item title="额定容量"  field="ratedCapacity" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.ratedCapacity" type="float" placeholder="请输入额定容量" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
					</vxe-form-gather>
					<vxe-form-gather span="12">
						<vxe-form-item title="温度探针数量"  field="tempNum" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.tempNum" type="number" placeholder="请输入温度探针数量" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
						<vxe-form-item title="最高可支持温度"  field="maxTemp" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.maxTemp" type="float" placeholder="请输入最高可支持温度" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
						<vxe-form-item title="最低可支持温度"  field="minTemp" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.minTemp" type="float" placeholder="请输入最低可支持温度" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
						<vxe-form-item title="额定电压"  field="ratedBatV" span="24" :item-render="{}" title-overflow>
							<template #default="params">
								<vxe-input v-model="params.data.ratedBatV" type="float" placeholder="请输入额定电压" clearable
									@input="$refs.xForm.updateStatus(params)"></vxe-input>
							</template>
						</vxe-form-item>
					</vxe-form-gather>
					<vxe-form-item align="center" span="24" :item-render="{}">
						<template #default>
							<vxe-button type="submit" status="primary">提交</vxe-button>
							<vxe-button type="reset">重置</vxe-button>
						</template>
					</vxe-form-item>
				</vxe-form>
			</template>
		</vxe-modal>
	</div>
</template>

<script>
	import {
		sava
	} from './index.js';
	import {
		checkNumber
	} from '@/shop/util/validator.js'
	export default {
		data() {
			return {
				formData2: {
					"batModel": "",//电池型号
					"exp": 0,//保质期（年）
					"id": 0,
					"maxTemp": 0,//最高可支持温度
					"minTemp": 0,//最低可支持温度
					"ratedBatV": 0,//额定电压
					"ratedCapacity": 0,//额定容量
					"singBatNum": 0,//电池单体数量
					"tempNum": 0//温度探针数量
				},
				loading2: false,
				formRules2: {
					batModel: [{
						required: true,
						message: '请输入型号名称',
						trigger: 'blur'
					}],
					exp: [{
						required: true,
						message: '请输入保质期',
						trigger: 'blur'
					}],
					maxTemp: [{
						required: true,
						message: '请输入最高可支持温度',
						trigger: 'blur'
					}],
					minTemp: [{
						required: true,
						message: '请输入最低可支持温度',
						trigger: 'blur'
					}],
					ratedBatV: [{
						required: true,
						message: '请输入额定电压',
						trigger: 'blur'
					}],
					ratedCapacity: [{
						required: true,
						message: '请输入额定容量',
						trigger: 'blur'
					}],
					singBatNum: [{
						required: true,
						message: '请输入电池单体数量',
						trigger: 'blur'
					}],
					tempNum: [{
						required: true,
						message: '请输入温度探针数量',
						trigger: 'blur'
					}]
				},
				dialogVisible: false,
				loading: false,

			};
		},
		created() {},
		methods: {
			handleClose(done) {
				this.resetForm('ruleForm');
				done();
			},
			open(item) {
				console.log(item)
				this.formData2 = {
					...item
				};
				this.dialogVisible = true;
			},
			submitEvent2(e) {
				console.log(e);
				this.loading2 = true
				setTimeout(() => {
					this.loading2 = false
					this.oldsava();
				}, 1000)
			},
			searchEvent() {
				this.msgSuccess('查询事件')
			},
			resetEvent() {
				this.msgSuccess('重置')
			},
			async oldsava() {
				this.loading = true;
				// this.ruleForm.token = localStorage.getItem('goods__token')
				// this.ruleForm.oldname = this.ruleForm.oname;
				let result = await sava(this.formData2);
				this.loading = false;
				if (result.code == 1) {
					if (this.formData2.id === 0) {
						this.msgSuccess("新增成功");
					} else {
						this.msgSuccess("修改成功");
					}

					this.resetForm('formData2');
					this.dialogVisible = false;
					this.$emit('oldlist')
				}

			}
		}
	};
</script>

<style></style>
